#coding=utf-8
import os
from stutils import *
from stscraper import *

from stsettings import datadir
HISTPRICEDIR = datadir + '/histprice'

codes = codes_from_datafile()
shcodes = [c for c in codes if c.startswith('6')]
szcodes = [c for c in codes if c.startswith('0')]

for c in szcodes:
    fn = '%s/%s.csv'%(HISTPRICEDIR, c)
    if not os.path.exists(fn):
        print c , ':no histprice csv file'
        continue
    try:
        data = get_tdprice(c)
    except NoPriceTodayError,e:
        print c
        print '\t',e
        continue
    
    f = open(fn, 'a')
    f.write(','.join(data))
    f.write('\n')
    f.close()
    
    print c